package com.core.zyyz.pcmc.controller;

import java.util.List;
import java.util.Map;

import com.core.zyyz.enums.NodeType;
import com.core.zyyz.pcmc.domain.DataPermissionEntity;
import org.apache.commons.collections4.MapUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.core.common.annotation.Log;
import com.core.common.core.controller.BaseController;
import com.core.common.core.domain.AjaxResult;
import com.core.common.enums.BusinessType;
import com.core.zyyz.pcmc.domain.PcmcOrgHierarchy;
import com.core.zyyz.pcmc.service.PcmcOrgHierarchyService;
import com.core.common.core.page.TableDataInfo;

/**
 * 机构层级Controller
 *
 * @author LiuFushun
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/pcmc/hierarchy")
public class PcmcOrgHierarchyController extends BaseController
{
    @Autowired
    private PcmcOrgHierarchyService pcmcOrgHierarchyService;

    /**
     * 查询机构层级列表
     */
    @PreAuthorize("@ss.hasPermi('pcmc:hierarchy:list')")
    @GetMapping("/list")
    public TableDataInfo list(PcmcOrgHierarchy pcmcOrgHierarchy)
    {
        startPage();
        List<PcmcOrgHierarchy> list = pcmcOrgHierarchyService.selectPcmcOrgHierarchyList(pcmcOrgHierarchy);
        return getDataTable(list);
    }

    /**
     * 获取机构层级详细信息
     */
    @PreAuthorize("@ss.hasPermi('pcmc:hierarchy:query')")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") String ID)
    {
        return success(pcmcOrgHierarchyService.selectPcmcOrgHierarchyByID(ID));
    }

    /**
     * 新增机构层级
     */
    @PreAuthorize("@ss.hasPermi('pcmc:hierarchy:add')")
    @Log(title = "机构层级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PcmcOrgHierarchy pcmcOrgHierarchy)
    {
        return toAjax(pcmcOrgHierarchyService.insertPcmcOrgHierarchy(pcmcOrgHierarchy));
    }

    /**
     * 修改机构层级
     */
    @PreAuthorize("@ss.hasPermi('pcmc:hierarchy:edit')")
    @Log(title = "机构层级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PcmcOrgHierarchy pcmcOrgHierarchy)
    {
        return toAjax(pcmcOrgHierarchyService.updatePcmcOrgHierarchy(pcmcOrgHierarchy));
    }

    /**
     * 删除机构层级
     */
    @PreAuthorize("@ss.hasPermi('pcmc:hierarchy:remove')")
    @Log(title = "机构层级", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable String[] IDs)
    {
        return toAjax(pcmcOrgHierarchyService.deletePcmcOrgHierarchyByIDs(IDs));
    }

    /**
     * 查询组织架构关系树机构节点
     * @param paraMap
     * @return
     */
    @PostMapping({"/query/tree/dept"})
    public TableDataInfo queryOrgHierarchyTreeDept(@RequestBody PcmcOrgHierarchy paraMap) {
        paraMap.setNodeType(NodeType.DEPARTMENT.getValue());
        DataPermissionEntity permission = new DataPermissionEntity();
        List<PcmcOrgHierarchy> list = this.pcmcOrgHierarchyService.queryOrgHierarchyTreeNode(permission,paraMap);
        return getDataTable(list);
    }

    /**
     * 查询组织架构关系树下的人员节点
     * @param paraMap
     * @return
     */
    @PostMapping({"/query/tree/employee"})
    public TableDataInfo queryOrgHierarchyTreeEmployee(@RequestBody PcmcOrgHierarchy paraMap) {
        paraMap.setNodeType(NodeType.EMPLOYEE.getValue());
        DataPermissionEntity permission = new DataPermissionEntity();
        List<PcmcOrgHierarchy> list = this.pcmcOrgHierarchyService.queryOrgHierarchyTreeNode(permission, paraMap);
        return getDataTable(list);
    }
}
